//
//  MeTopHeaderCell.swift
//  XiaoJingMallSwift
//
//  Created by beisheng03 on 2017/7/27.
//  Copyright © 2017年 beisheng. All rights reserved.
//

import UIKit

class MeTopHeaderCell: BaseTableViewCell {
    
    @IBOutlet weak var imgBgView: UIView!
    
    @IBOutlet weak var imgView: UIImageView!

    @IBOutlet weak var nameNabel: UILabel!
    
    @IBOutlet weak var certifiImage: UIImageView!
    
    @IBOutlet weak var privilegeLabel: UILabel!
    
    @IBOutlet weak var loginBtn: UIButton!
    
    @IBOutlet weak var privilegeBtn: UIButton!
    
    
    @IBOutlet weak var storeBtn: UIButton!
    
    @IBOutlet weak var footPrintBtn: UIButton!
    
    @IBOutlet weak var nameLabelConstr: NSLayoutConstraint!
    
    
    var model : PersonalDataModel?{
    
    
        didSet{
            
            nameNabel.text = model?.nickname
            
            if model != nil{
                
            
                imgView.sd_setImage(with: URL(string :model!.avator), placeholderImage: UIImage.defaulIconImage(), options: []) { (image, _, _, _) in
                    
                    
                    
                }
                
            }
            
    


            if UserViewModel.shared.userIsLogin() == false {
                
                certifiImage.isHidden = true
                privilegeLabel.isHidden = true
                loginBtn.isHidden = false
                privilegeBtn.isHidden = true
                nameLabelConstr.constant = 12
                storeBtn.setTitle("商品收藏", for: .normal)
                footPrintBtn.setTitle("我的足迹", for: .normal)

                return
            } else {
                
                certifiImage.isHidden = false
                privilegeLabel.isHidden = false
                loginBtn.isHidden = true
                privilegeBtn.isHidden = false
                nameLabelConstr.constant = 0

            }
            

            
            if let temp = model?.favorites_goods {
                
                storeBtn.setTitle("商品收藏" + "(" + temp + ")", for: .normal)
                
            }else{
            
                storeBtn.setTitle("商品收藏", for: .normal)

            }
            
            if let temp = model?.foot_prints {
                
                footPrintBtn.setTitle("我的足迹" + "(" + temp + ")", for: .normal)
                
            }else{
            
                footPrintBtn.setTitle("我的足迹", for: .normal)


            }
            
            
            if model?.is_authentic == "1" {
                
                certifiImage.image = UIImage(named: "certification7")
                
            } else {
                
                certifiImage.image = UIImage(named: "certification6")

            }
            
          
        
        
        }
    
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        privilegeLabel.addCornerAndBorder(borderColor: nil, borderWidth: 0.0, masksToBounds: true, cornerRadius: 9.0)
        
        imgBgView.addCornerAndBorder(borderColor: nil, borderWidth: 0.0, masksToBounds: true, cornerRadius: 32)
        
        imgView.addCornerAndBorder(borderColor: nil, borderWidth: 0.0, masksToBounds: true, cornerRadius: 30)
        
        
    }
    
    
    @IBAction func loginBtnDidTap(_ sender: UIButton) {
        
        
        performIsLoginJump(aSelector: #selector(test), target: self)
        
        
    }
    
    func test() {}
    
    @IBAction func privilegeBtnDidTap(_ sender: UIButton) {
        
        let settingVC  = VipPrivilegeVC()
        
        vipPushTag = true

        viewController().navigationController?.pushViewController(settingVC, animated: true)
        
   
    }
    
    @IBAction func settingBtnDidTap(_ sender: UIButton) {
        
        pushSettingViewController()
//        performIsLoginJump(aSelector: #selector(pushSettingViewController), target: self)
        
 
    }
    
    
    @IBAction func storeBtnDidTap(_ sender: UIButton) {
        
        
        
        performIsLoginJump(aSelector: #selector(storeVC), target: self)
        
        
    }
    
    
    @IBAction func footPrintBtnDidTap(_ sender: UIButton) {
        
        performIsLoginJump(aSelector: #selector(footPrintVC), target: self)
        
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
    
    func pushSettingViewController() {
        
        let settingVC  = SettingController()
        
        let temp = viewController() as! PersonalController
        
        settingVC.model = temp.dataModel
        
        temp.navigationController?.pushViewController(settingVC, animated: true)
        
        
    }
    
    
    
    func storeVC() {
        
        let settingVC  = FootPrintStoreVC()
        
        settingVC.navigationItem.title = "商品收藏"
        
        settingVC.urlStr = "mobile/index.php?c=member_favorites&a=favorites_list"
        
        viewController().navigationController?.pushViewController(settingVC, animated: true)
        
        
        
    }

    
    func footPrintVC() {
        
        let settingVC  = FootPrintStoreVC()
        
        settingVC.navigationItem.title = "我的足迹"
        
        settingVC.urlStr = "mobile/index.php?c=member_goodsbrowse&a=browse_list"
        
        viewController().navigationController?.pushViewController(settingVC, animated: true)
        
        
        
    }

    
    
}
